package com.kawaiior.asoulworld.items.weapon;

import com.kawaiior.asoulworld.items.AsWeaponBase;
import com.kawaiior.asoulworld.util.EntityUtil;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.init.MobEffects;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ActionResult;
import net.minecraft.util.EnumHand;
import net.minecraft.world.World;

public class ItemAvaDrill extends AsWeaponBase {

    public ItemAvaDrill(String name) {
        super(name);
        this.max_damage = 14;
        this.max_damage = 3072;
    }

    @Override
    public boolean canHarvestBlock(IBlockState blockIn)
    {
        return true;
    }

    @Override
    public float getDestroySpeed(ItemStack stack, IBlockState state)
    {
        Block block = state.getBlock();
        if (block == Blocks.OBSIDIAN)
        {
            return 100.0F;
        }
        if (block == Blocks.DIRT)
        {
            return 3F;
        }
        if (block == Blocks.SAND)
        {
            return 3F;
        }
        return 20F;
    }

    @Override
    public int getMaxItemUseDuration(ItemStack stack)
    {
        return 10;
    }

    @Override
    public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn) {
        if (worldIn.isRemote) return super.onItemRightClick(worldIn, playerIn, handIn);

        playerIn.getCooldownTracker().setCooldown(this, 400);
        EntityUtil.ApplyBuff(playerIn, MobEffects.RESISTANCE, 4, 1);
        playerIn.world.createExplosion(playerIn, playerIn.posX, playerIn.posY, playerIn.posZ, 3, false);
        playerIn.getHeldItem(handIn).damageItem(64, playerIn);

        return super.onItemRightClick(worldIn, playerIn, handIn);
    }

}
